/*
 * @lc app=leetcode.cn id=146 lang=javascript
 *
 * [146] LRU 缓存
 */

function ListNode(val, next, pre) {
  this.value = (val===undefined ? 0 : val)
  this.next = (next===undefined ? null : next)
  this.pre = (pre===undefined ? null : pre)
}

// @lc code=start
/**
* @param {number} capacity
*/
var LRUCache = function (capacity) {
  this.size = 0;
  this.capacity = capacity;
  this.head = null;
  this.last = null;
  this.lruHash = {};
  return this;
};

LRUCache.prototype.setLast = function (cur) {
  const pre = cur.pre;
  const next = cur.next;
  if (this.size === 1) {
      return;
  }
  if (cur === this.last) {
      return;
  }
  if (cur === this.head) {
      this.last.next = next;
      this.head = this.last;
      cur.next = null;
      this.last = cur;
      return;
  }
  pre.next = next;
  this.last.next = cur;
  cur.pre = this.last;
  cur.next = null;
  this.last = cur;
}

/**
* @param {number} key
* @return {number}
*/
LRUCache.prototype.get = function (key) {
  if (!this.lruHash[key]) {
      return -1;
  }

  const cur = this.lruHash[key];
  this.setLast(cur);

  return cur.value;
};

/**
* @param {number} key
* @param {number} value
* @return {void}
*/
LRUCache.prototype.put = function (key, value) {
  if (this.lruHash[key]) {

  }

  return null;
};
// ["LRUCache","put","put","put","put","get","get","get","get","put","get","get","get","get","get"]\n[[3],[1,1],[2,2],[3,3],[4,4],[4],[3],[2],[1],[5,5],[1],[2],[3],[4],[5]]
/**
* Your LRUCache object will be instantiated and called as such:
* var obj = new LRUCache(capacity)
* var param_1 = obj.get(key)
* obj.put(key,value)
*/
// @lc code=end
